import django_mysql.models
from django.db import models

# Create your models here.
from users.models import User


class WavFiles(models.Model):
    types = (
        ('0', '普通话'),
        ('1', '粤语'),
    )
    wav = models.CharField(verbose_name="图片", max_length=200)
    text = models.CharField(max_length=200, verbose_name="", default="")
    typ = django_mysql.models.EnumField(choices=types, verbose_name="类别")

    class Meta:
        db_table = 'Wav'
        verbose_name = '用户绘画记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.text + " " + self.typ


class Histories(models.Model):
    wav = models.ForeignKey('WavFiles', on_delete=models.CASCADE)
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, related_name="history")

    class Meta:
        db_table = 'History'
        verbose_name = '历史'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.name + " " + self.wav.text + " " + self.wav.typ
